package com.briup.jz.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.jz.bean.BasePrivilege;
import com.briup.jz.service.BasePrivilegeService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description="BasePrivilege(权限表)相关接口")
@Validated
@RestController
@RequestMapping("/basePrivilege")
public class BasePrivilegeController {
	@Autowired
    private BasePrivilegeService basePrivilegeService;
	
	@ApiOperation(value = "查询所有权限")
    @GetMapping("query")
    public Message query(String name){
        List<BasePrivilege> list = basePrivilegeService.query(name);
        return MessageUtil.success(list);
    }

    @ApiOperation(value = "通过id删除权限")
    @GetMapping("deleteById")
    public Message deleteById( String name){
    	basePrivilegeService.deleteById(name);
        return MessageUtil.success("删除成功");
    }
    
  
    @ApiOperation(value = "保存或更新权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "主键",paramType = "form"),
            @ApiImplicitParam(name="name",value = "权限名",paramType = "form"),
            @ApiImplicitParam(name="description",value = "描述",paramType = "form"),
            @ApiImplicitParam(name="route",value = "导航路线（路径）",paramType = "form"),
            @ApiImplicitParam(name="routeName",value = "路线名称",paramType = "form"),
            @ApiImplicitParam(name="type",value = "类型",paramType = "form"),
            @ApiImplicitParam(name="icon",value = "图标",paramType = "form"),
            @ApiImplicitParam(name="hidden",value = "隐藏",paramType = "form"),
            @ApiImplicitParam(name="num",value = "数量",paramType = "form"),
            @ApiImplicitParam(name="parentId",value = "父类id",paramType = "form"),
            
    })
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(BasePrivilege basePrivilege){
    	basePrivilegeService.saveOrUpdate(basePrivilege);
        return MessageUtil.success("更新成功");
    }
    
    
	@ApiOperation(value = "查询所有子权限")
    @GetMapping("selectChilder")
    public Message selectChilder(){
        List<BasePrivilege> list = basePrivilegeService.selectChilder();
        return MessageUtil.success(list);
    }
}
